package com.sankuai.inf.leaf.segment.dao;

import com.sankuai.inf.leaf.segment.model.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author final
 * @description
 * @date 2019-09-10 11:13
 */
public interface UserMapper {


    @Select("SELECT id, user_name, password,salt,ctime FROM user WHERE user_name = #{username}")
    @Results(value = {
            @Result(column = "id", property = "id"),
            @Result(column = "user_name", property = "username"),
            @Result(column = "password", property = "password"),
            @Result(column = "salt", property = "salt"),
            @Result(column = "ctime", property = "ctime")
    })
    User getUserByUserName(@Param("username") String username);

    @Insert("INSERT  INTO `user` (user_name,`password`,salt) VALUES(#{username},#{password},#{salt})")
    int insertUser(@Param("user") User user);

    @Select("SELECT id, user_name,ctime FROM user ORDER BY ctime DESC")
    @Results(value = {
            @Result(column = "id", property = "id"),
            @Result(column = "user_name", property = "username"),
            @Result(column = "ctime", property = "ctime")
    })
    List<User> listUser();

    @Insert("UPDATE `user` SET `password`= #{password},salt= #{salt} WHERE id =#{id}")
    int updateUser(@Param("user") User user);
}
